import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:taonile/config/config.dart';
import 'package:url_launcher/url_launcher.dart';

import '../http/api.dart';

class MineAbout extends StatefulWidget {
  const MineAbout({Key? key}) : super(key: key);

  @override
  State<MineAbout> createState() => _MineAboutState();
}

class _MineAboutState extends State<MineAbout> {
  var wechat = '';
  var phone = '';
  var copyright = '';
  String version = '';

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  getData() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();

    dynamic result = await Api.contactUs();
    var jsonResult = jsonDecode(jsonEncode(result));
    if (jsonResult['code'] == 1) {}
    setState(() {
      version = packageInfo.version;

      wechat = jsonResult['data']['wechat'];
      phone = jsonResult['data']['phone'];
      copyright = jsonResult['data']['copyright'];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg2,
      appBar: AppBar(
        title: const Text('联系我们'),
        centerTitle: true,
      ),
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Stack(
          children: [
            // Image.asset(
            //   'assets/images/login_bg.png',
            //   width: double.infinity,
            //   height: 300.w,
            //   fit: BoxFit.fill,
            // ),
            Container(
              width: double.infinity,
              height: double.infinity,
              padding: EdgeInsets.symmetric(vertical: 50.w, horizontal: 38.w),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  //大LOGO
                  Container(
                    alignment: Alignment.center,
                    width: double.infinity,
                    child: Container(
                      margin: EdgeInsets.only(top: 30.w),
                      width: 152.w,
                      height: 152.w,
                      padding: EdgeInsets.all(0.w),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        // color: Config.colorWhite, // 底色
                        boxShadow: [
                          BoxShadow(
                            blurRadius: 8, //阴影范围
                            spreadRadius: 3, //阴影浓度
                            color: Config.colorDivider, //阴影颜色
                            offset: Offset(4.w, 8.w),
                          ),
                        ],
                        borderRadius: BorderRadius.circular(0.w),
                      ),
                      child: SizedBox(
                        width: double.infinity,
                        height: double.infinity,
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(0.w),
                          child: Image.asset('assets/images/launcher.png'),
                        ),
                      ),
                    ),
                  ),
                  Padding(padding: EdgeInsets.only(top: 20.w)),
                  // Text(
                  //   "淘你乐",
                  //   style: TextStyle(color: Config.colorText1, fontSize: 30.w),
                  // ),
                  // Padding(padding: EdgeInsets.only(top: 5.w)),
                  Text(
                    "v$version",
                    style: TextStyle(color: Config.colorText1, fontSize: 25.w),
                  ),
                  Padding(padding: EdgeInsets.only(top: 30.w)),
                  Column(
                    children: [
                      Container(
                        padding: const EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          border:
                              Border(bottom: BorderSide(color: Config.colorDivider, width: 1.w)),
                        ),
                        height: 130.w,
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Expanded(
                              flex: 1,
                              //aboutEntity.data[index].title
                              child: Text(
                                "官方微信",
                                softWrap: true,
                                style: TextStyle(color: (Config.colorText1), fontSize: 25.w),
                              ),
                            ),
                            Expanded(
                              flex: 1,
                              //aboutEntity.data[index].text
                              child: InkWell(
                                onTap: () {
                                  Clipboard.setData(ClipboardData(text: wechat));
                                  EasyLoading.showToast("复制成功");
                                },
                                child: Text(
                                  wechat,
                                  softWrap: false,
                                  textAlign: TextAlign.right,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: (Config.colorText1), fontSize: 25.w),
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
                      Container(
                        padding: const EdgeInsets.all(10),
                        decoration: BoxDecoration(
                          border:
                              Border(bottom: BorderSide(color: Config.colorDivider, width: 1.w)),
                        ),
                        height: 130.w,
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Expanded(
                              flex: 1,
                              //aboutEntity.data[index].title
                              child: Text(
                                "官方电话",
                                softWrap: true,
                                style: TextStyle(color: (Config.colorText1), fontSize: 25.w),
                              ),
                            ),
                            Expanded(
                              flex: 1,
                              //aboutEntity.data[index].text
                              child: InkWell(
                                onTap: () {
                                  launchUrl(Uri.parse('tel:$phone'));
                                },
                                child: Text(
                                  phone,
                                  softWrap: false,
                                  textAlign: TextAlign.right,
                                  overflow: TextOverflow.ellipsis,
                                  style: TextStyle(color: (Config.colorText1), fontSize: 25.w),
                                ),
                              ),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ],
              ),
            ),
            Positioned(
              bottom: 0.w,
              child: Container(
                alignment: Alignment.center,
                height: 150.w,
                width: 750.w,
                child: Text(
                  copyright,
                  style: TextStyle(color: Config.colorText1, fontSize: 22.w),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
